<%@page contentType="text/html;charset=utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>商品列表</title>
<script type="text/javascript" src="../../js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="../../js/sweetalert2.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/list.css">
<script type="text/javascript">
	/*图片预览*/
	function showPreview(previewObj){
		var picture = $(previewObj).attr("data-picture");
		var pname = $(previewObj).attr("data-pname");
		Swal.fire({
			title:pname,
			html:"<img src='"+picture+"' style='width:361px;height:240px'>",
			showCloseButton:true,
			showConfirmButton:false
		});
	}
	/*删除*/
	function del(delObj){
		var pname = $(delObj).attr("data-pname");
		var id = $(delObj).attr("data-id");
		var picture = $(delObj).attr("data-picture");
		Swal.fire({
			title:"确认要删除["+pname+"]商品吗？",
			html:"<img src='"+picture+"' style='width:361px;height:240px'>",
			showCancelButton:true,
			confirmButtonText:"是",
			cancelButtonText:"否"
		}).then(function(result){
			if(result.value == true){
				//alert("你点了'是'按钮");
				$.ajax({
					url:"management?method=gdelete&id="+id,
					type:"get",
					dataType:"json",
					success:function(json){
						if(json.result=="ok"){
							window.location.reload();
						}else{
							Swal.fire({
								title:json.result
							})
						}
					}
				})
			}
		})

	}
</script>
</head>
<body>
	<div class="container">
		<fieldset>
			<legend>商品列表</legend>
			<div style="height: 40px">
				<a href="/management?method=gshow_create" class="btn-button">新增</a>
			</div>
			<!-- 商品列表 -->
			<table cellspacing="0px">
				<thead>
					<tr style="width: 150px;">
						<th style="width: 100px">编号</th>
						<th style="width: 150px">名称</th>
						<th style="width: 100px">分类</th>
						<th style="width: 100px">起拍价</th>
						<th style="width: 400px">描述</th>
						<th style="width: 100px">加价幅度</th>
                        <th style="width: 100px">评估价</th>
						<th style="width: 150px">开拍时间</th>
                        <th style="width: 150px">结束时间</th>
						<th style="width: 150px">操作</th>
					</tr>
				</thead>
				<c:forEach items="${pageModel.pageData }" var="goods" >
					<tr>
						<td>${goods.goods_id }</td>
						<td>${goods.goods_name }</td>
						<td style="color: green">${goods.second_cname}</td>
						<td style="color: red"><fmt:formatNumber value="${goods.low_price }" pattern="￥,000.00" ></fmt:formatNumber></td>
						<td>${goods.goods_desc }</td>
						<td style="color: red"><fmt:formatNumber value="${goods.price_markup }" pattern="￥,000.00"></fmt:formatNumber></td>
                        <td style="color: red"><fmt:formatNumber value="${goods.appraisal_price }" pattern="￥,000.00"></fmt:formatNumber></td>
                        <td><fmt:formatDate value="${goods.start_time}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate> </td>
                        <td><fmt:formatDate value="${goods.end_time}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate> </td>
						<td>
							<a class="oplink" data-picture="${goods.goods_picture }" data-pname="${goods.goods_name }" href="javascript:void(0)" onclick="showPreview(this)">预览</a>
							<a class="oplink" href="/management?method=gshow_update&gid=${goods.goods_id}">修改</a>
							<a class="oplink" href="javascript:void(0)" data-id="${goods.goods_id }" data-pname="${goods.goods_name }" data-picture="${goods.goods_picture }" onclick="del(this)">删除</a>
						</td>
					</tr>
				</c:forEach>
			</table>
			<!-- 分页组件 -->
			<ul class="page">
				<li><a href="/management?method=glist&p=1">首页</a></li>
				<li><a href="/management?method=glist&p=${pageModel.hasPreviousPage?pageModel.page-1:1 }">上页</a></li>
				<c:forEach begin="1" end="${pageModel.totalPages }" var="pno" step="1">
				<li ${pno==pageModel.page?"class='active'":"" }>
					<a href="/management?method=glist&p=${pno }">${pno }</a>
				</li>
				</c:forEach>
				<li><a href="/management?method=glist&p=${pageModel.hasNextPage?pageModel.page+1:pageModel.totalPages }">下页</a></li>
				<li><a href="/management?method=glist&p=${pageModel.totalPages }">尾页</a></li>
			</ul>
		</fieldset>
	</div>

</body>
</html>
